<?php

namespace App\Http\Controllers\Eaxm;

use App\Eaxm\Account;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class AccountController extends Controller
{
    /**
     * @param Request $request
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * User: Mr.zhao
     * Date: 2021/5/20 9:01
     * 展示页面+分页+搜索
     */
    public  function  account_index(Request $request)
    {
        //接受要搜索的内容
        $keyword = $request->get('keyword');
        //先进行匹配
        $search = '%'.$keyword.'%';
        //查询所有数据
        $account_data = Account::indexTest($search);
        return view('Account.account-index',compact('account_data','keyword'));
    }

    /**
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * User: Mr.zhao
     * Date: 2021/5/20 9:13
     * 展示添加页面
     */
    public  function account_create()
    {
        return view('Account.account-create');
    }
    public  function account_save(Request $request)
    {
        //接受所有数据
        $data_all = $request->all();
        print_r($data_all['password']);




    }

    public  function account_edit($id)
    {
      $one_data = Account::editTest($id);
      return view('Account.account-edit',compact('one_data'));
    }
    public  function account_update(Request $request)
    {
        $id = $request->get('id');
        $data_all = $request->except('_token','password_confirmation');

        $result = Account::updateTest($id,$data_all);
        if($result == 1){
            return redirect(route('account_index'));
        }else{
            return redirect(route('account_edit',['id'=>$id]));
        }

    }
}
